package com.androidcourse.shounews.Toast;
import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.androidcourse.shounews.R;

public class MyCustomToast extends Toast {
    private Context context;
    private int resourceId;
    private String message;
    public static int SUCCESS= R.drawable.toast_success_24;
    public static int ERROR=R.drawable.toast_error_24;
    /**
     * Construct an empty Toast object.  You must call {@link #setView} before you
     * can call {@link #show}.
     *
     * @param context The context to use.  Usually your {@link Application}
     *                or {@link Activity} object.
     */
    public MyCustomToast(Context context, int resourceId, String message) {
        super(context);
        this.context=context;
        this.resourceId=resourceId;
        this.message=message;
        showToast();
    }
    public MyCustomToast(Context context, String message) {
        super(context);
        this.context=context;
        this.message=message;
        showToast();
    }
    public void showToast(){
        LayoutInflater inflater=LayoutInflater.from(context);
        View view=inflater.inflate(R.layout.my_custom_toast,null);
        TextView textView=view.findViewById(R.id.my_custom_toast_message);
        ImageView imageView=view.findViewById(R.id.my_custom_toast_img);
        imageView.setImageResource(resourceId);
        textView.setText(message);
        setView(view);
        setGravity(Gravity.BOTTOM,0,150);
        super.show();
    }
}
